package ca.cbc.panacea.elixir.util;

import ca.cbc.panacea.elixir.entity.PanaceaInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.management.RuntimeErrorException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author : Arash Bizhanzadeh <arash.bizhanzadeh@cbc.ca>
 *         Date: 11-11-18
 *         Time: 5:13 PM
 *         CBC.ca All rights reserved.
 */
public enum ElixirProperties {
    instance;

    private  Logger logger = LoggerFactory.getLogger(ElixirProperties.class);
    private Properties properties;
    private ElixirProperties(){
       properties = new Properties();
       InputStream is = null;
        try {
             is = ElixirProperties.class.getClassLoader().getResourceAsStream("elixir.properties");
            properties.load(is);
        } catch (IOException e) {
            logger.error("Error reading the elixir.properties file");
            throw new RuntimeException(e);
        }finally {
            if(is != null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public String getRootDir(){
        return properties.getProperty("root.dir");
    }

    public String getDirectoryFor(PanaceaInstance instance){
        return ElixirProperties.instance.getRootDir()
                    +  instance.getDirectory() + "/";
    }


    public Object getOutputDir() {
        return properties.getProperty("output.dir");
    }

    public String getLoggingDir() {
        return properties.getProperty("log.dir");
    }
}
